package com.jhgk.jhcee.queue.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/13 16:19.
 */
@Configuration
public class RabbitMqConfig {

    // 数据队列
    public final static String DATA_QUEUE = "dataQueue";

    public final static String TOPIC_QUEUE_ONE = "topic_queue_one";

    public final static String TOPIC_QUEUE_TWO = "topic_queue_two";

    public final static String FANOUT_QUEUE_ONE = "fanout_queue_one";

    public final static String FANOUT_QUEUE_TWO = "fanout_queue_two";

    public final static String TOPIC_EXCHANGE = "topic_exchange";

    public final static String FANOUT_EXCHANGE = "fanout_exchange";

    public final static String TOPIC_ROUTINGKEY_ONE = "common_key";

    public final static String TOPIC_ROUTINGKEY_TWO = "*.key";

    // direct模式
    @Bean
    public Queue directQueue() {
        return new Queue(DATA_QUEUE,true);
    }

    // topic 订阅者队列
    @Bean
    public Queue topicQueueOne() {
        return new Queue(TOPIC_QUEUE_ONE,true);
    }

    @Bean
    public DirectExchange topExchange() {
        return new DirectExchange(TOPIC_EXCHANGE,true,false);
    }

    @Bean
    public Binding topExchangeBingingOne() {
        return BindingBuilder.bind(topicQueueOne()).to(topExchange()).with(TOPIC_QUEUE_ONE);
    }
}
